package src.hash;

public class no383 {
    //赎金信，判断字符串1能不能由字符串2组成

    public static void main(String[] args) {
        String str1 = "aa";
        String str2 = "aab";
        System.out.println(canConstruct(str1, str2));
    }

    public static boolean canConstruct(String ransomNote, String magazine) {
        if (ransomNote.length() > magazine.length()) {
            return false;
        }
        int[] chars = new int[26];
        for (char i : magazine.toCharArray()) {
            chars[i - 'a'] ++;
        }
        for (char i : ransomNote.toCharArray()) {
            chars[i - 'a'] --;
        }

        for (int i : chars) {
            if (i < 0) {
                return false;
            }
        }

        return true;
    }
}
